package com.zxw.third.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zxw.common.api.ApiResult;
import com.zxw.common.api.PageResult;
import com.zxw.common.constant.ApiConst;
import com.zxw.common.entity.bizjob.BizJobEntity;
import com.zxw.common.entity.bizjob.BizJobListQuery;
import com.zxw.common.entity.bizjob.BizJobQuery;
import com.zxw.common.entity.bizjob.BizJobVO;
import com.zxw.common.enums.ResultCode;
import com.zxw.third.service.BizJobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 * 任务接口
 * </p>
 *
 * @author zhanxuewei
 * @since 2022-10-12
 */
@Api(tags = "任务接口", description = "BizJobController")
@RestController
@RequestMapping(ApiConst.API_PREFIX + "/third/job")
public class BizJobController {

    @Autowired
    private BizJobService bizJobService;

    @ApiOperation("添加")
    @PostMapping("/save")
    public ApiResult<ResultCode> save(@RequestBody BizJobQuery bizJobQuery) {
        bizJobService.save(bizJobQuery);
        return ApiResult.success(ResultCode.SUCCESS);
    }

    @ApiOperation("列表条件分页查询")
    @GetMapping("/pageList")
    public ApiResult<PageResult<BizJobVO>> pageList(BizJobListQuery bizJobListQuery) {
        IPage<BizJobVO> ipage = bizJobService.pageList(bizJobListQuery);
        return ApiResult.success(PageResult.restPage(ipage, ipage.getRecords()));
    }

    @ApiOperation("批量添加")
    @PostMapping("/saveBatch")
    public ApiResult<ResultCode> saveBatch(@RequestBody List<BizJobQuery> list) {
        bizJobService.saveBatch(list);
        return ApiResult.success(ResultCode.SUCCESS);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public ApiResult<ResultCode> update(@RequestBody BizJobQuery bizJobQuery) {
        bizJobService.updateById(bizJobQuery);
        return ApiResult.success(ResultCode.SUCCESS);
    }

    @ApiOperation("批量删除")
    @PostMapping("/deletes")
    public ApiResult<ResultCode> deletes(@RequestBody List<String> ids) {
        bizJobService.removeByIds(ids);
        return ApiResult.success(ResultCode.SUCCESS);
    }

    @ApiOperation("详情")
    @GetMapping("/detail/{id}")
    public ApiResult<BizJobVO> detail(@PathVariable("id") String id) {
        BizJobEntity bizJobEntity = bizJobService.getById(id);
        BizJobVO bizJobVO = new BizJobVO();
        BeanUtils.copyProperties(bizJobEntity, bizJobVO);
        return ApiResult.success(bizJobVO);
    }

}

